package com.briup.sms.web.controller;

import com.briup.sms.entity.Banner;
import com.briup.sms.service.BannerService;
import com.briup.sms.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/banner")
@Api(tags = "轮播模块")
@CrossOrigin
public class BannerController {
    @Autowired
    BannerService service;

    @GetMapping("/findBanners")
    @ApiOperation("分页查询轮播信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "title",value = "轮播标题",defaultValue = "",required = false),
                    @ApiImplicitParam(name = "active",value = "轮播是否禁用",required = false),
                    @ApiImplicitParam(name = "pageSize",value = "分页每页数据条数",required = true),
                    @ApiImplicitParam(name = "pageNum",value = "页码",required = true)
            }
    )
    public Result findBanners(String title, Boolean active, Integer pageSize, Integer pageNum){
        PageInfo<Banner> banners = service.findBanners(title, active, pageSize, pageNum);
        return  Result.success(banners);
    }

    @PostMapping("/saveBanner")
    @ApiOperation("新增/修改轮播信息")
    public Result save(@RequestBody Banner banner){
        service.save(banner);
        return  Result.success();
    }
    @ApiOperation("修改轮播状态")
    @PutMapping("/updateActive/{id}")
    public Result updateActive(@PathVariable  Integer id){
        service.updateActive(id);
        return  Result.success();
    }

}
